/*
 * $Id: Globals.h,v 1.4 2007/06/21 10:49:01 baconevi Exp $
 *
   Copyright 2005-2009 Chung, Hyung-Hwan.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an  BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

#ifndef _GLOBALS_H_
#define _GLOBALS_H_

#include <xp/types.h>
#include <xp/macros.h>
#include <xp/net/socket.h>
#include <xp/utl/log.h>
#include <xp/Exception.hpp>
#include <xp/bas/Mutex.hpp>
#include <xp/sys/Path.hpp>
#include "AppEnv.h"
#include "MainApp.h"

using namespace xp;
using namespace xp::bas;
using namespace xp::sys;

enum
{
	APP_MODE_FOREGROUND = (1 << 0),
	APP_MODE_CHILD      = (1 << 1)   // for _WIN32 only
};

extern int          app_mode;
extern xp_log_t     app_log;
extern MainApp*     app_main;
extern Mutex        app_main_mutex;
extern Path         app_path;
extern AppEnv       app_env;
extern AppEnvPath   app_env_path;
extern Mutex        app_env_mutex;

#define APP_NAME                      XP_T("app")
#define APP_INI_FILE                  XP_T("app.ini")
#define APP_LOG_FILE                  XP_T("app.log")

#ifdef _WIN32
#define APP_EVENT_NAME                XP_T("Local\\app_quit_event")
#endif

#define APP_FILE_PERM                 0600

#define APP_YES                       XP_T("yes")
#define APP_NO                        XP_T("no")
#define APP_GATE_TCP_SERVICE          XP_QUOTE(0)
#define APP_GATE_MAX_CONNECTIONS_MIN  0  // 0 means unlimited, however
#define APP_GATE_MAX_CONNECTIONS_MAX  100
#define APP_GATE_MAX_CONNECTIONS      5
#define APP_GATE_TIMEOUT_MIN          -1  // -1: unlimited
#define APP_GATE_TIMEOUT_MAX          3600000
#define APP_GATE_TIMEOUT              -1
 
#define APP_LOGGING_TARGET_FILE       XP_T("file")
#define APP_LOGGING_TARGET_SYSLOG     XP_T("syslog")
#define APP_LOGGING_TARGET_CONSOLE    XP_T("console")

#define APP_ENV_LOGGING_TARGET        XP_T("MAIN*LOGGING_TARGET")
#define APP_ENV_LOGGING_LEVEL         XP_T("MAIN*LOGGING_LEVEL")

#define APP_ENV_GATE_ENABLE_TCP       XP_T("GATE*ENABLE_TCP")
#define APP_ENV_GATE_TCP_SERVICE      XP_T("GATE*TCP_SERVICE")
#define APP_ENV_GATE_TCP_LOCAL_ONLY   XP_T("GATE*TCP_LOCAL_ONLY")
#define APP_ENV_GATE_MAX_CONNECTIONS  XP_T("GATE*MAX_CONNECTIONS")
#define APP_ENV_GATE_TIMEOUT          XP_T("GATE*TIMEOUT")

#endif
